'''
给定一个字符串s，找出至多包含两个不同字符串的最长子串t，并返回该子串的长度。
示例1：
输入：“eceba”
输出：3
解释：t是“ece”，长度为3
示例2：
输入：”ccaabbb“
输出：5
解释：t是”aabbb“，长度为5
'''
# s = input()

# def get_result(s):
#     n = len(s)
#     if n <=2:
#         return n
#
#     l = 0
#     r = 0
#     # count={}
#     res=0
#     for l in range(n):
#         for r in range(n):
#             temp = s[l:r+1]
#             sts= list(set(temp))
#             if len(sts) <= 2:
#                 res = max(res,r-l+1)
#             else:
#                 break
#     return res
def get_result(s):
    n = len(s)
    if n<=2:
        return n
    l = 0
    r = 0
    res=0
    count={}
    total = 0
    while r < n:
        while total <= 2:
            for c in count:
                if count[c] !=0:
                    total +=1
            if s[r] not in count:
                count[s[r]] =1
            else:
                count[s[r]] +=1
            r +=1
        res=max(res,r-l)
        if s[l] in count:
            count[s[l]] -=1
            l +=1
    return res






print(get_result("ccaabbb"))

